#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) 
    {
        sort(nums.begin(), nums.end());
        int begin = 0;
        while (nums.size() > 2)
        {
            int i = begin+1;
            if ((nums[i] == nums[begin]))
            {
                while (i<nums.size() && nums[i] == nums[begin])
                {
                    i++;                
                }
                nums.erase(nums.begin() + begin, nums.begin()+i);
                
            }
            else begin+=1;
        }
        return nums;
    }
};

